﻿@using System.Data
@{
    ViewBag.Title = "";
    Layout = "~/Areas/Admin/Views/Shared/AdminLayout.cshtml";
  

}


<input name="id" id="id" type="hidden" value="0" />
<table style="float: left;font-size: 12px;">
    <tr>
        <td><label>角色名称</label></td>
        <td><input type="text" id="name" name="name" style="width: 200px;" /></td>
    </tr>
    <tr>
        <td><label>启用</label></td>
        <td>
          <input type="checkbox" checked="checked" id="isexit"/>
        </td>
    </tr>
    <tr>
        <td><label>备注</label></td>
        <td><input type="text" id="remark" name="remark" style="width: 300px;" /></td>
    </tr>
    <tr>
        <td colspan="2">
            <div class="botton" style="margin-left: 50px;" onclick="edit()">保存</div>
            <div class="botton" style="margin-left: 50px;" onclick="javascript: history.go(-1);">取消</div>
        </td>
    </tr>
</table>

<script>
    var id = "@ViewData["id"]";
    if (parseFloat(id) > 0) {
        $.post("@Url.Action("GetOneData")", { id: id }, function(data) {
            var obj = jQuery.parseJSON(data);
            $("#id").val(obj[0].Id);
            $("#name").val(obj[0].RoleName);
            $("#remark").val(obj[0].Remark);
            if (obj[0].IsExit == 0) {
                $("#isexit").attr("checked", "checked");
            } else {
                $("#isexit").removeAttr("checked");
            }
           
        });
    }

    function edit() {
        var name = $("#name").val();
        var remark = $("#remark").val();

        if (name.replace(/\ +/g, "") == "") {
            alert("请输入菜单名称！");
            return false;
        }
        if (remark.replace(/\ +/g, "").length > 100) {
            alert("备注最多只能输入100个字！");
            return false;
        }
        var isexit = 0;
        if (!$("#isexit").is(":checked")) {
            isexit = 1;
        }
        $.post("@Url.Action("Edit")", { id: id, remark: remark, name: name, isexit: isexit }, function (row) {
            if (row > 0) {
                alert("操作成功！");

            } else {
                alert("添加失败！");
            }
            location.href = "@Url.Action("Index")";

        });
    }

</script>

